package com.linkage.bss.crm.packagemgr.smo.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.linkage.bss.commons.dao.Page;
import com.linkage.bss.commons.exception.SmoException;
import com.linkage.bss.crm.packagemgr.bmo.IPackageCheckBMO;
import com.linkage.bss.crm.packagemgr.bmo.IPackageStatusBMO;
import com.linkage.bss.crm.packagemgr.model.Area;
import com.linkage.bss.crm.packagemgr.model.Channel;
import com.linkage.bss.crm.packagemgr.model.CheckResult;
import com.linkage.bss.crm.packagemgr.smo.IPackageStatusSMO;
import com.linkage.bss.crm.packagemgr.util.Constant;

/**
 *
 * 包状态管理
 *
 * @author  Administrator
 * @version  [版本号, 2013-5-10]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class PackageStatusSMOImpl implements IPackageStatusSMO {

	IPackageStatusBMO packageStatusBMO = null;

	IPackageCheckBMO packageCheckBMO = null;

	public IPackageStatusBMO getPackageStatusBMO() {
		return packageStatusBMO;
	}

	public IPackageCheckBMO getPackageCheckBMO() {
		return packageCheckBMO;
	}

	public void setPackageCheckBMO(IPackageCheckBMO packageCheckBMO) {
		this.packageCheckBMO = packageCheckBMO;
	}

	public void setPackageStatusBMO(IPackageStatusBMO packageStatusBMO) {
		this.packageStatusBMO = packageStatusBMO;
	}

	public CheckResult publishPackage(Long packageID, List<Integer> areaList, List<Integer> channelList, Long staffID) {

		getPackageStatusBMO().publishPackage(packageID, areaList, channelList, staffID);

		return null;

	}

	public void stopUsePackage(Long packageId, Long staffID) {
		getPackageStatusBMO().stopUsePackage(packageId, staffID);
	}

	public void startUsePackage(Long packageId, Long staffID) {
		//验证包
		CheckResult checkResult = getPackageCheckBMO().checkPackageByPackageId(packageId);

		if (checkResult.isResult()) {
			getPackageStatusBMO().startUsePackage(packageId, staffID);
		} else {
			throw new SmoException(Constant.CHECK_FALSE, checkResult.getErrMsg());
		}
	}

	public List<Area> getAreaByName(String name, Integer areaId, Page page) {

		return getPackageStatusBMO().getAreaByName(name, areaId, page);
	}

	public int getAreaCountByName(String name, Integer areaId) {
		return getPackageStatusBMO().getAreaCountByName(name, areaId);
	}

	public List<Channel> getChannelByName(String channelName, Integer mangerAreaID, Page page) {
		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("name", channelName);
		queryMap.put("aeraId", mangerAreaID);

		try {
			return getPackageStatusBMO().getChannelByName(queryMap, page);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SmoException(Constant.GET_PACKAGE_2_CHENNEL_FALSE, "发布渠道错误 !");
		}

	}

	public int getChannelByNameCount(String channelName, Integer mangerAreaID) {

		Map<String, Object> queryMap = new HashMap<String, Object>();
		queryMap.put("name", channelName);
		queryMap.put("aeraId", mangerAreaID);
		try {
			return getPackageStatusBMO().getChannelByNameCount(queryMap);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SmoException(Constant.GET_PACKAGE_2_CHENNEL_FALSE, "发布渠道错误 !");
		}

	}

	public List<Channel> queryPackage2Channel(Long packageId) {

		try {
			return getPackageStatusBMO().queryPackage2Channel(packageId);
		} catch (Exception e) {
			e.printStackTrace();
			throw new SmoException(Constant.GET_PACKAGE_2_CHENNEL_FALSE, "获取包发布渠道错误 !");
		}
	}

	public List<Area> queryPackage2Area(Long packageId) {
		return getPackageStatusBMO().queryPackage2Area(packageId);
	}

}
